using System;
using Microsoft.Practices.ServiceLocation;
using Sogeti.Guidelines.WCF.Hosting;
using Spring.Context;
using Spring.Context.Support;
using Spring.Objects.Factory;

namespace Sogeti.Guidelines.Spring.WCF
{
    public class SpringXmlConfigContainerProvider : IContainerProvider
    {
        private IListableObjectFactory _factory;

        public IServiceLocator CreateContainer()
        {
            return new CommonServiceLocator.SpringAdapter.SpringServiceLocatorAdapter(_factory);
        }

        public virtual void EnsureConfiguration()
        {
            _factory = ContextRegistry.GetContext();
        }
    }
}